import xyRequest from '..'

// POST /user/task/page 任务单条件分页查询
interface TaskQueryParams {
  page: number
  pageSize: number
  projectType?: string
  taskName?: string
  taskRole?: string
  taskPeriod?: number
  taskScoreMax?: number
  taskScoreMin?: number
}
export function queryTasksWithConditions(params: TaskQueryParams) {
  return xyRequest.post({
    url: '/user/task/page',
    data: params
  })
}

// GET /user/task/findByTaskId/{taskId} 通过id查找任务单
export function getTaskDetail(taskId: number) {
  return xyRequest.get({
    url: `/user/task/findByTaskId/${taskId}`
  })
}

//DELETE /user/task/delete/{taskId} 通过id删除任务单
export function deleteTask(taskId: string) {
  return xyRequest.delete({
    url: `/user/task/delete/${taskId}`
  })
}

//PUT /user/task/update 更新任务单
export function updateTaskDetail(data: any) {
  return xyRequest.put({
    url: '/user/task/update',
    data
  })
}

//GET /user/task/findByProjectId/{projectId} 通过项目id查找任务单
export function getTasksByProjectId(projectId: string) {
  return xyRequest.get({
    url: `/user/task/findByProjectId/${projectId}`
  })
}

// GET /user/task/updateState/{taskId} 验收任务
export function acceptTask(taskId: string) {
  return xyRequest.get({
    url: `/user/task/updateState/${taskId}`
  })
}

//添加任务单
export function addTask(data: any) {
  return xyRequest.post({
    url: '/user/task/add',
    headers: {
      'Content-Type': 'Application/JSON'
    },
    data: JSON.stringify(data)
  })
}

//GET /user/task/recommend 推荐任务
export function recommendTask(minCount: number) {
  return xyRequest.get({
    url: `/user/task/recommend?minCount=${minCount}`
  })
}
